#include<iostream>
#include<math.h>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=1e5+10;
int a[N];
int cha[N];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n;
    ll ans=0;
    ll sum=0;
    cin >> n;
    for(int i=1;i<=n;i++) cin >> a[i];
    for(int i=1;i<=n/2;i++)
    {
        cha[i]=a[i]-a[n-i+1];
    }
    for(int i=1;i<=n/2;i++)
    {
        if(cha[i]==0){
            continue;
        }
        else if(cha[i]<0){
            if(i!=(n/2)&&cha[i+1]<0){
                int mi=min(abs(cha[i]),abs(cha[i+1]));
                sum+=mi;
                cha[i]+=mi;
                cha[i+1]+=mi;
            }
            sum+=abs(cha[i]);
            cha[i]=0;
        }else if(cha[i]>0){
            if(i!=(n/2)&&cha[i+1]>0){
                int mi=min(abs(cha[i]),abs(cha[i+1]));
                sum+=mi;
                cha[i]-=mi;
                cha[i+1]-=mi;
            }
            sum+=abs(cha[i]);
            cha[i]=0;
        }
    }
    ans=sum;
    cout << ans;
    return 0;
}